﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WpfApplication2.ViewModels.Afiliado;
using WpfApplication2.UserControls;
using WpfApplication2.Helpers;

namespace WpfApplication2.Views.Afiliado
{
    /// <summary>
    /// Interaction logic for ConsultarAfiliado.xaml
    /// </summary>
    public partial class BuscarAfiliado : Page
    {
        #region Properties

        public string Titulo 
        {
            get
            {
                return lblTitulo.Content.ToString();
            }
            set
            {
                lblTitulo.Content = value;
            }
        }
        
        public Visibility BtnEditarAfiliadoVisibility
        {
            get
            {
                return btnEditar.Visibility;
            }
            set
            {
                btnEditar.Visibility = value;
            }
        }

        public Visibility BtnVentaOrdenesVisibility
        {
            get
            {
                return btnVentaOrdenes.Visibility;
            }
            set
            {
                btnVentaOrdenes.Visibility = value;
            }
        }

        public Visibility BtnConsultarAfiliadoVisibility
        {
            get
            {
                return btnConsultar.Visibility;
            }
            set
            {
                btnConsultar.Visibility = value;
            }
        }

        public Visibility BtnEditarHistoriaVisibility
        {
            get
            {
                return btnEditarHistoria.Visibility;
            }
            set
            {
                btnEditarHistoria.Visibility = value;
            }
        }

        public Visibility BtnConsultarHistoriaVisibility
        {
            get
            {
                return btnConsultarHistoria.Visibility;
            }
            set
            {
                btnConsultarHistoria.Visibility = value;
            }
        }

        private BuscarAfiliadoViewModel context
        {
            get
            {
                return (BuscarAfiliadoViewModel)DataContext;
            }
        }

        #endregion

        public BuscarAfiliado(Instancias instancias, OperacionBusquedaAfiliado op)
        {
            InitializeComponent();
            if (op == OperacionBusquedaAfiliado.Consultar)
            {
                Titulo = "CONSULTA DE AFILIADO";
                BtnConsultarAfiliadoVisibility = Visibility.Visible;
            }
            else if (op == OperacionBusquedaAfiliado.Editar)
            {
                Titulo = "EDICION DE AFILIADO";
                BtnEditarAfiliadoVisibility = Visibility.Visible;
            }
            else if (op == OperacionBusquedaAfiliado.VenderOrdenes)
            {
                Titulo = "GESTION DE ORDENES";
                BtnVentaOrdenesVisibility = Visibility.Visible;
            }
            else if (op == OperacionBusquedaAfiliado.NuevaHistoria)
            {
                Titulo = "NUEVA HISTORIA CLINICA";
                BtnEditarHistoriaVisibility = Visibility.Visible;
            }
            else if (op == OperacionBusquedaAfiliado.ConsultarHistoria)
            {
                Titulo = "CONSULTAR HISTORIA CLINICA";
                BtnConsultarHistoriaVisibility = Visibility.Visible;
            }
            DataContext = new BuscarAfiliadoViewModel(instancias);
        }


        private void EnableDisableButtons(TextBox tb)
        {
            Image img = (tb.Parent as StackPanel).Children[1] as Image;
            if (string.IsNullOrEmpty(tb.Text))
                img.Source = new BitmapImage(new Uri("../../Images/delete_btn.png", UriKind.Relative));
            else
                img.Source = new BitmapImage(new Uri("../../Images/delete_btn_hover.png", UriKind.Relative));
        }

        private void textbox_TextChanged(object sender, TextChangedEventArgs e)
        {
            EnableDisableButtons(sender as TextBox);
        }

        
        private void BtnLimpiar_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Image img = sender as Image;
            TextBox tb = (img.Parent as StackPanel).Children[0] as TextBox;
            if (tb.Text.Length > 0)
            {
                img.Source = new BitmapImage(new Uri("../../Images/delete_btn.png", UriKind.Relative));
                tb.Text = string.Empty;
            }
        }
    }
}
